package com.yubest.security.bean;

import com.yubest.security.consts.Consts;
import lombok.Data;

import java.io.Serializable;

@Data
public class Response<T> implements Serializable {

    private Integer code;

    private String msg;

    private T data;

    public Response(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <E> Response<E> ok(E data) {
        return new Response<>(Consts.SUCCESS_CODE, null, data);
    }

    public static <E> Response<E> error(String msg) {
        return error(Consts.ERROR_CODE, msg);
    }

    public static <E> Response<E> error(Integer code, String msg) {
        return new Response<>(code, msg, null);
    }
}
